﻿using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using ORMapping;


namespace BLL
{
    public class UserBLL
    {
        public void AddUser(User user)
        {
            UserDAL dal = new UserDAL();
            user.LoginName = user.LoginName.ToUpper();
            dal.AddUser(user);
        }

        public void UpdateUser(User user)
        {
            UserDAL dal = new UserDAL();
            dal.UpdateUser(user);
        }

        public void DeleletUser(User user)
        {
            UserDAL dal = new UserDAL();
            dal.DeleteUser(user);
        }

        public IList<User> GetAllUsers(string strHQL, System.Collections.Generic.List<HQLParameter> hp)
        {
            UserDAL dal = new UserDAL();
            return dal.GetAllUsers(strHQL,hp);
        }

        public bool Login(string strLoginName, String strPasswd)
        {
            strLoginName = strLoginName.Trim();
            strPasswd = strPasswd.Trim();
            if (String.Empty == strLoginName)
            {
                return false;
            }

            if (String.Empty == strPasswd)
            {
                return false;
            }

            UserDAL dal = new UserDAL();
            var u = dal.Login(strLoginName, strPasswd);
            if (u != null)            
            {
                HYSession.Session.SetValue(u.GetType().Name, u);
                return true;
            }
            return false;
        }
    }
}
